'use strict'
import React from 'react'
import style from '../css.css'
import { goIndex, goLive } from '../../config/goto'
import config from '../../config'

class List extends React.Component {
  constructor (props) {
    super(props)
    this.state = {}
    this._handleItem = this._handleItem.bind(this)
  }

  _handleItem () {
    // 正在直播的主播进入／或者在糗事百科的直播页面进入的不响应
    if (config.isAnchor || config.qiubaizhibo) {
      console.log('正在直播的主播进入／或者在糗事百科的直播页面进入的不响应')
      return
    }
    if (config.inapp_info) {
      console.log('在自家APP内，跳转直播页／个人主页')
      const { uid, source, platform_id, live } = this.props.item
      if (uid == null || source == null || platform_id == null || live == null) { return }
      else {
        const args = { uid, source, platform_id }
        if (live == 1) {
          // 直播间
          goLive(args)
        }
        else {
          // 个人主页
          goIndex(args)
        }
      }

      return
    }
    else {
      console.log('没有在自家APP内，跳去下载')
      window.location.href = config.download
      return
    }
  }
  _renderLive (item) {
    if (!this.props.item) { return }
    const { live } = this.props.item
    if (live == 1) {
      return (
        <div className={style.itemLive}></div>
      )
    }
    else {
      return
    }
  }

  render () {
    const { index, item } = this.props
    const defaultHead = '../../image/default.png'
    console.log(item)
    return (

      <div className={index == 1 ? style.king2 : style.king1}>
        <div className={style.kingicon} onClick={this._handleItem}>
          <i></i>
          <img src={item ? item.headurl : ''} alt=''/>
          {this._renderLive(1)}
        </div>
        <span className={index == 2 ? style.kings2 : style.kings}></span>
        <span className={style.text}>{item ? item.name : '  '}</span>
        <span className={style.text}>{item ? item.num : '  '}</span>
      </div>

    )
  }
}

export default List

